//
//  AddressBookListViewController.m
//  PigMarket
//
//  Created by mac on 2019/6/26.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AddressBookListViewController.h"
#import "ChatListCell.h"

@interface AddressBookListViewController ()<UITableViewDelegate,UITableViewDataSource>
/**
 myTableView
 */
@property (nonatomic , strong) UITableView *myTableView;
/**
 dataArr
 */
@property (nonatomic , strong) NSMutableArray *dataArr;
/**
 addressBookdArr
 */
@property (nonatomic , strong) NSMutableArray *addressBookdArr;
@end

@implementation AddressBookListViewController

#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"通讯录朋友";
    [self setUpView];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

#pragma mark - init method
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self.view addSubview:self.myTableView];
}

- (void) initLayout {
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

- (void) initAction {
    
}

- (void)initData {
   
//手机联系人
    @weakify(self);
    [[AddressBookManager sharedManager] queryAddressBookCompletionBlock:^(NSMutableArray *dataArr,NSFileManager *file) {
        @strongify(self);

//        [self.addressBookdArr addObjectsFromArray:dataArr];
//        [self uploadAddressBookRequest];
        [[[PigMarketApi sharedInstance] uploadAddressBookWithFileName:@"myJson.json" file:file] subscribeNext:^(NSNull * _Nullable x) {
        
        } error:^(NSError * _Nullable error) {
            
            @strongify(self);
            [self handlingError:error];

        }];

    }];
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ChatListCell *cell = [ChatListCell cellWithTableView:tableView];
    AddressBookModel *model = self.dataArr[indexPath.row];
    PMLog(@"====%@",model.tels);

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
#pragma mark - target action

#pragma mark - private method
- (void)uploadAddressBookRequest {
//    [PigMarketApi sharedInstance] uploadAddressBookWithFileName:@"filename" file:<#(id)#>
}
#pragma mark - getter and setter
- (UITableView *)myTableView {
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.rowHeight = 70;
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
    }
    return _myTableView;
}
- (NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return _dataArr;
}
- (NSMutableArray *)addressBookdArr {
    if (!_addressBookdArr) {
        _addressBookdArr = [[NSMutableArray alloc] init];
    }
    return _addressBookdArr;
}
@end

